Use var at global scope (outside of all functions) to declare a global variable:

<script>
var yourGlobalVariable;
function foo() {
    // ...
}
</script>

Alternately, assign to a property on window:

<script>
function foo() {
    window.yourGlobalVariable = ...;
}
</script>